﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThaireInvestmentWeb.Util;
using ThaireInvestmentWeb.WcfSerivce;

namespace ThaireInvestmentWeb.Models
{
    public class ManageLoanModel
    {
        public SearchLoanFilter SearchFilter { get; set; }
        public ManageLoanModel()
        {
            Init();
        }
        void Init()
        {
            CompanyList = new List<SelectListItem> { WebUtil.SelectListSelectDefault() };
            StatusList = new List<SelectListItem> { WebUtil.SelectListAllDefault() };
            LoanTypeList = new List<SelectListItem> { WebUtil.SelectListAllDefault() };

            if (SearchFilter == null)
                SearchFilter = new SearchLoanFilter();

            if (_data != null)
            {
                foreach (var item in _data.Companies)
                {
                    CompanyList.Add(new SelectListItem() { Text = item.CompanyNameTh, Value = item.CompanyId.ToString() });
                }
                foreach (var item in _data.LoanTypes)
                {
                    LoanTypeList.Add(new SelectListItem() { Text = item.Key, Value = item.ValueTH });
                }
                foreach (var item in _data.Statuses)
                {
                    StatusList.Add(new SelectListItem() { Text = item.Key, Value = item.ValueTH });
                }
                ////type
                //LoanTypeList.Add(item: new SelectListItem() { Selected = false, Text = "Pending", Value = "1" });
                //LoanTypeList.Add(item: new SelectListItem() { Selected = false, Text = "Closed", Value = "2" });
            }
        }
        public void ClearFilterAndData()
        {
            Init();
        }

        static LoanHeaderScreenData _data;

        public static ManageLoanModel BuildModel(LoanHeaderScreenData data)
        {
            _data = data;
            return new ManageLoanModel();
        }
        public IList<LoansHeaderAdapter> Result { get; set; }

        [Required(ErrorMessage = "โปรดระบุ")]
        public int? SelectedCompany
        {
            get { return SearchFilter.Company; }
            set { SearchFilter.Company = value; }
        }
        public IList<SelectListItem> CompanyList { get; set; }
        public int? SelectedLoanType
        {
            get { return SearchFilter.LoanType; }
            set { SearchFilter.LoanType = value; }
        }
        public IList<SelectListItem> LoanTypeList { get; set; }

        public string SelectedStatus
        {
            get { return SearchFilter.Status; }
            set { SearchFilter.Status = value; }
        }
        public IList<SelectListItem> StatusList { get; set; }

        public string ContractNumber
        {
            get { return SearchFilter.ContractNumber; }
            set { SearchFilter.ContractNumber = value; }
        }
        public string BorrowerName
        {
            get { return SearchFilter.BorrowerName; }
            set { SearchFilter.BorrowerName = value; }
        }
        [DataType(DataType.Date)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        [Display(Name = "Contract Start Date")]
        public DateTime? ContractStartDate
        {
            get { return SearchFilter.ContractStartDate; }
            set { SearchFilter.ContractStartDate = value; }
        }
        [DataType(DataType.Date)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        [Display(Name = "Between ")]
        public DateTime? ContractEndDate
        {
            get { return SearchFilter.ContractEndDate; }
            set { SearchFilter.ContractEndDate = value; }
        }


        [Display(Name = "Loan Balance ")]
        public decimal? LoanBalanceStart
        {
            get { return SearchFilter.LoanBalanceStart; }
            set { SearchFilter.LoanBalanceStart = value; }
        }
                [Display(Name = "Between ")]
        public decimal? LoanBalanceEnd
        {
            get { return SearchFilter.LoanBalanceEnd; }
            set { SearchFilter.LoanBalanceEnd = value; }
        }

        public String SearchBtn { get; set; }
        public String ResetBtn { get; set; }


    }
}